/**
 *
 * 户外便民市场安全隐患排查
 *
 */
$(function () {
    // 初始化 Vue 实例
    const app = Vue.createApp({
        data() {
            return {
                // 表单数据
                formData: {
                },
                showLogOut: false,
                logOutForm: {},
            };
        },
        mounted() {
            this.getDetail()

        },
        methods: {
            previewImg(url){
                vant.showImagePreview([url])
            },
            // 注销
            setLogOut(){
                const vm = this;
                $.ajax({
                    url: `${globalApi.hosts}${listApi['market'].off}`,
                    method: "post",
                    dataType: "json",
                    headers: {
                        "content-type": "application/json",
                    },
                    data: JSON.stringify({
                        ...vm.logOutForm
                    }),
                    success: function (res) {
                        if (res.code === 200) {
                            vant.showNotify({type: 'primary', message: '注销成功'});
                            vm.showLogOut = false;
                            vm.logOutForm = {};
                            vm.getDetail();
                        }
                    }
                })
            },
            // 处置
            setDisposalComplete(){
                const vm = this;
                $.ajax({
                    url: `${globalApi.hosts}${listApi['market'].dispose}`,
                    method: "post",
                    dataType: "json",
                    headers: {
                        "content-type": "application/json",
                    },
                    data: JSON.stringify({
                        caseId: vm.formData.caseId,
                    }),
                    success: function (res) {
                        if (res.code === 200) {
                            vant.showNotify({type: 'primary', message: '处置成功'});
                            vm.getDetail();
                        }
                    }
                })

            },
            // 归档
            setPigeonhole(){
                const vm = this;
                $.ajax({
                    url: `${globalApi.hosts}${listApi['market'].archive}${vm.formData.caseId}`,
                    method: "post",
                    dataType: "json",
                    headers: {
                        "content-type": "application/json",
                    },
                    data: JSON.stringify({
                        caseId: vm.formData.caseId,
                    }),
                    success: function (res) {
                        if (res.code === 200) {
                            vant.showNotify({type: 'primary', message: '归档成功'});
                            vm.getDetail();
                        }
                    }
                })

            },
            getDetail(){
                const vm = this;
                const queryParameters = paramsUrl(location.href)
                $.ajax({
                    url: `${globalApi.hosts}${listApi['market'].info}${queryParameters.id}`,
                    method: "get",
                    dataType: "json",
                    success: function (res) {
                        if (res.code === 200) {
                            vm.formData = res.data;
                            vm.logOutForm = {
                                caseId: vm.formData.caseId,
                                completeInfo: '',
                            }
                        }
                    }
                })

            },
            onClickLeft() {
                history.back();
            },
            onFailed(errorInfo) {
                console.log("failed", errorInfo);
            },
            saveForm(){
                $.ajax({
                    url: `${globalApi.hosts}${listApi['market'].case}`,
                    method: "POST",
                    dataType: "json",
                    data: this.formData,
                    success: function (res) {
                        if (res.code === 200) {
                            history.back();
                        }
                    }
                })
            },
        },
    });

    app.use(vant);
    app.mount("#app");

})